import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 三角序列
 * User: DELL
 * Date: 2024-05-24
 * Time: 9:03
 */
public class Main10 {
    static ArrayList<Integer> list;
    static ArrayList<Long> preSum;

    /**
     * 本题只考虑想办法获取那 50% 的数据的分数
     * 总体上就是使用一个数组来记录每个点的高度，然后高度 h 进行二分枚举
     * 同时维护一个前缀和来检验是否有满足条件的点
     *
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int maxH = 0;
        list = new ArrayList<>();
        preSum = new ArrayList<>();
        preSum.add(0L);
        while (n-- > 0) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            maxH = Math.max(maxH, a);
            long pre = preSum.get(preSum.size() - 1);
            ;
            if (b == 0) {
                for (int i = 1; i <= a; i++) {
                    list.add(i);
                    pre += i;
                    preSum.add(pre);
                }
            } else {
                for (int i = a; i > 0; i--) {
                    list.add(i);
                    pre += i;
                    preSum.add(preSum.get(preSum.size() - 1) + i);
                }
            }
        }
        while (m-- > 0) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int v = scanner.nextInt();
            if (preSum.get(r) - preSum.get(l - 1) < v) {
                System.out.println(-1);
                continue;
            }
            int left = 1;
            int right = maxH;
            while (left < right) {
                int mid = (left + right) / 2;
                if (check(l, r, v, mid)) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            System.out.println(left);
        }
    }

    /**
     * 大于返回 true
     * 小于返回 false
     */
    private static boolean check(int l, int r, int v, int h) {
        int sum = 0;
        for (int i = l; i <= r; i++) {
            int temp = list.get(i - 1);
            if (temp > h) {
                sum += h;
            } else {
                sum += temp;
            }
            if (sum >= v) {
                return true;
            }
        }
        return false;
    }
}
